package model;

import java.math.BigInteger;
import java.sql.SQLException;

public class Model {
	MaintananceModel maintanance = new MaintananceModel();
	UserModel user = new UserModel();
	public Model(){
		
	}
	public void putMoneyToAcount(BigInteger idCard,int amount) throws SQLException{
		user.putMoneyToAcount(idCard, amount);
	}
	
	public void putMoneyToATM(int amount10,int amount50,int amount100,int amount200) throws Exception{
		if(( amount10<0)||(amount10>1000)||( amount50<0)||(amount50>1000)||( amount100<0)||(amount100>1000)||( amount200<0)||(amount200>1000))
			throw new Exception("Invalid data");
		int[] mas=maintanance.getMoneyUAN();
		maintanance.putMoneyUAN(mas[0]+amount10, mas[1]+amount50, mas[2]+amount100, mas[3]+amount200);
			
	}
	public void withdraw(int amount) throws NoMoneyExeption, SQLException{
		maintanance.withdrawMoney(amount);
	}
	public void withdrawTen(int kilk) throws SQLException, NoMoneyExeption{
		maintanance.withdrawTen(kilk);
	}
	public void withdrawFifty(int kilk) throws SQLException, NoMoneyExeption{
		maintanance.withdrawFifty(kilk);
	}
	public void withdrawHundred(int kilk) throws SQLException, NoMoneyExeption{
		maintanance.withdrawHundred(kilk);
	}
	public void withdrawTwoHandred(int kilk) throws SQLException, NoMoneyExeption{
		maintanance.withdrawTwoHandred(kilk);
	}
	public int [] getMoney() throws SQLException{
		return maintanance.getMoneyUAN();
	}
	
	public int getAmountOf10() throws SQLException{
		return maintanance.getMoneyUAN()[0];
	}
	public int getAmountOf50() throws SQLException{
		return maintanance.getMoneyUAN()[1];
	}
	public int getAmountOf100() throws SQLException{
		return maintanance.getMoneyUAN()[2];
	}
	public int getAmountOf200() throws SQLException{
		return maintanance.getMoneyUAN()[3];
	}
	
	
	
	public int takeMoney(BigInteger idCard,int pin,int amountToTake) throws SQLException,Exception{
		int balance= user.getBalancle(idCard, pin);
		if (balance-amountToTake<0){
			throw new  Exception();
		}
		user.setBalance(idCard, balance-amountToTake);
		return balance-amountToTake;
	}
	
	public boolean checkCard(BigInteger idCard) throws SQLException{
		return user.checkForCardId(idCard);
	}
	public boolean checkAccount(BigInteger idCard,int pin) throws SQLException{
		return user.checkAcount(idCard, pin);
	}
	
	public int getBalance(BigInteger idCard,Integer pin) throws SQLException{
		return user.getBalancle(idCard, pin);
	}
}
